import { makeAutoObservable } from 'mobx'
import request from '@/utils/request'
import { setToken, getToken, deleteToken } from '@/utils/token'
class Login {
  constructor() {
    // 开启响应式
    makeAutoObservable(this)
  }
  token = getToken() || ''
  // 设置token
  getToken = async (data) => {
    const res = await request({
      method: 'POST',
      url: 'authorizations',
      data
    })
    this.token = res.data.token
    // 把token存储到本地
    setToken(this.token)
  }
  // 退出登录
  loginOut = () => {
    deleteToken()
    this.token = ''
  }
}
export default Login